﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PetroMentor.Service.Common;
using PetroMentor.Service.Manager;

namespace PetroMentor.Service
{
    /// <summary>
    /// QueryHanlder 的摘要说明
    /// </summary>
    public class QueryHanlder : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //查询模块名，就是类名
            string module = context.Request.QueryString[Consts.MODULE];

            //获取数据页
            int pagenumber = Convert.ToInt32(context.Request.QueryString[Consts.PAGE_NUMBER]);
            //获取数据页大小，每页记录数
            int pagesize = Convert.ToInt32(context.Request.QueryString[Consts.PAGE_SIZE]);
            string where = "1=1";
            //查询条件
            if(context.Request.QueryString[Consts.WHERE] != null && context.Request.QueryString[Consts.WHERE] != "")
            {
                where = context.Request.QueryString[Consts.WHERE];
            }
            string orderby = "CJSJ desc";
            if (context.Request.QueryString[Consts.ORDERBY] != null && context.Request.QueryString[Consts.ORDERBY] != "")
            {
                orderby = context.Request.QueryString[Consts.ORDERBY];
            }

            //module = "T_CFG_MODULE";
            //pagenumber = 1;
            //pagesize = 10;


            string strOp = SerializeManager.SerializeQueryEntities(module, pagenumber, pagesize, where, orderby);

            ////模块
            //string strModule = context.Request.QueryString["MODULE"];

            //string temp = SerializeManager.SelectEntitiesResult("", 1, 10, "");

            context.Response.ContentType = "text/plain";
            context.Response.Write(strOp);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}